<?php
require_once 'lib.php';
require_once 'config.php';
require_once 'sql.php';
$confg = arrConfig();
function converts($img,$cat,$id)
{
    $confg = arrConfig();
    $im = $db->fetchOne("SELECT imstring FROM `category` WHERE id = ?",$cat);
    $path_im = $confg['path_im'];
    $path_com = $confg['path_com'];
    $path_com_thumd = $_SERVER['DOCUMENT_ROOT']."/thumb";
    $path_imag = $_SERVER['DOCUMENT_ROOT']."/thumb/".date("Y")."/".date("m");
    $dir = $_SERVER['DOCUMENT_ROOT']."/thumb/".date("Y");
    if(!is_dir($dir)) mkdir($dir);
    if(!is_dir($path_imag)) mkdir($path_imag);
    exec ("$path_im $img  $im $path_imag/$id.jpg");
    exec ("$path_com -gravity southwest $path_com_thumd/watermark.png $path_imag/$id.jpg $path_imag/$id.jpg");
    // обновить статус, добавить в базу картинку
}
function imagarn($url,$cat,$id)
{
$in = file_get_contents($url);

$oXml = ParseXml($in);

$post = $oXml->xpath("//img[@src]");

foreach ($post as $posts)
{
    
        //echo "<br>".$posts['src'];
    if(strpos($posts['src'],"/imags/")){
        $img =  $posts['src'];
        converts($img,$cat,$id);
        
        
    }
}

}
function imagarn($url)
{
$in = file_get_contents($url);

$oXml = ParseXml($in);

$post = $oXml->xpath("//img[@src]");

foreach ($post as $posts)
{
    
        //echo "<br>".$posts['src'];
    if(strpos($posts['src'],"/imags/")){
        return $posts['src'];
    }
}

}
function imagarn($url)
{
$in = file_get_contents($url);

$oXml = ParseXml($in);

$post = $oXml->xpath("//img[@src]");

foreach ($post as $posts)
{
    
        //echo "<br>".$posts['src'];
    if(strpos($posts['src'],"/imags/")){
        return $posts['src'];
    }
}

}
function imagarn($url)
{
$in = file_get_contents($url);

$oXml = ParseXml($in);

$post = $oXml->xpath("//img[@src]");

foreach ($post as $posts)
{
    
        //echo "<br>".$posts['src'];
    if(strpos($posts['src'],"/imags/")){
        return $posts['src'];
    }
}

}
?>